package com.example.ui.learn.util;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.AlertDialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.renderscript.Program.TextureType;
import android.support.v4.widget.SearchViewCompat.OnCloseListenerCompat;
import android.text.Html;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.BaseExpandableListAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.example.entity.TestEntity;
import com.example.huashangapp.R;
import com.example.net.AnalyzingJson;
import com.example.net.NetRequest;

import com.example.ui.sharte.util.SRecommend;
import com.example.util.AsyncLoadImage;
import com.google.gson.JsonObject;

//选课中心

public class MyListViewAdapter2 extends BaseAdapter {
	private LayoutInflater inflater;
	private ArrayList<CurriculumCenter2> list;
	private AsyncLoadImage asyncLoadImage;
	String id;
	public int current;
	public static int type;//2 huashang  1center
	public MyListViewAdapter2(Context mContext,ArrayList<CurriculumCenter2> list,AsyncLoadImage ali){
		inflater = LayoutInflater.from(mContext);
        this.list=list;
        this.asyncLoadImage=ali;
	}
	public ArrayList<CurriculumCenter2> getCcInfos() {
		return list;
	}

	public void setCcInfos(ArrayList<CurriculumCenter2> list) {
		this.list = list;
		if (list == null) {
			this.list = new ArrayList<CurriculumCenter2>();
		}
	}	
	class Holder {
		ImageView icon;
		LinearLayout l;
		TextView teacher;
		TextView studentnum;
		TextView textTitle;
		Button btn_false;
		
		TextView content1;
		TextView content2;
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}
	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return null;
	}
	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Holder holder;
		CurriculumCenter2 cc2 = list.get(position);
		final String url =cc2.getThumb();
		
		final ImageView imageView;
		id = cc2.getIntro();		
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.a_cca_item, null);
			holder = new Holder();
			holder.l=(LinearLayout) convertView.findViewById(R.id.cca_l2);
			holder.icon = (ImageView) convertView.findViewById(R.id.aci_icon);
			holder.icon.setBackgroundResource(R.drawable.aci_book);
			holder.textTitle = (TextView) convertView
					.findViewById(R.id.item01_list_text_title);			
			
			holder.teacher = (TextView) convertView
					.findViewById(R.id.aci_teacher);
		
			holder.studentnum = (TextView) convertView
					.findViewById(R.id.aci_studentnum);
			holder.btn_false = (Button) convertView
					.findViewById(R.id.aci_btnfalse);	
			switch (type) {
			case 1:
				holder.btn_false.setText("点击收听");
				break;
			case 2:
				holder.btn_false.setText("点击收听");
				break;
			default:
				break;
			}
			
			holder.content1 = (TextView) convertView
					.findViewById(R.id.aci_content1);
			holder.content2 = (TextView) convertView
					.findViewById(R.id.aci_content2);
            imageView = (ImageView)convertView.findViewById(R.id.item01_list_img);
			convertView.setTag(holder);
		} else {
			imageView = (ImageView)convertView.findViewById(R.id.item01_list_img);
			holder = (Holder) convertView.getTag();
		}
		if(current!=position){
			holder.l.setVisibility(View.GONE);
			holder.btn_false.setVisibility(View.GONE);
		}
		
		imageView.setTag(url);	
		asyncLoadImage.imageLoader.displayImage(url, imageView,asyncLoadImage.options);
			imageView.setTag(url);
  
		
		holder.textTitle.setText(cc2.getTitle());
		holder.teacher.setText(cc2.getTitle1());
		switch (type) {
		case 1:
			holder.studentnum.setText(cc2.getLearnnum() + "人正在学");
			break;
		case 2:
			holder.studentnum.setText(cc2.getLearnnum()+"人已收听");
			break;

		default:
			break;
		}				
		holder.content1.setText(Html.fromHtml(cc2.getContent1()));				
		holder.content2.setText(Html.fromHtml(cc2.getContent2()));		
		return convertView;
	}




}
